package com.jcl.recruit.log.logic;

import com.jcl.core.utils.CollectionUtils;
import com.jcl.recruit.log.dao.ResumeLogDao;
import com.jcl.recruit.log.model.ResumeLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @ClassName ResumeLogLogic

 * @Author yyliu
 * @Date 2018/10/31 16:30
 * @Version 1.0
 **/
@Component
public class ResumeLogLogic {

    @Autowired
    private ResumeLogDao resumeLogDao;

    public List<Integer> findResumeIds(String corpCode, Integer userId, Integer category) {
        List<ResumeLog> list = resumeLogDao.findListByCorp(corpCode, userId, category);
        List<Integer> resumeIds = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(list)) {
            for (ResumeLog entity : list) {
                resumeIds.add(entity.getResumeId());
            }
        }

        return resumeIds;
    }


    public ResumeLog addResumeLog(String corpCode,
                                  Integer userId,
                                  Integer resumeId,
                                  String content,
                                  Integer category,
                                  String resumeType) {

        ResumeLog log = new ResumeLog();
        log.setLog(content);
        log.setCategory(category);
        log.setResumeType(resumeType);
        log.setUserId(userId);
        log.setResumeId(resumeId);
        log.setCorpCode(corpCode);
        log.setCreateTime(new Date());
        resumeLogDao.insert(log);
        return log;
    }

    public List<ResumeLog> findList(Integer resumeId) {
        return resumeLogDao.findList(resumeId);
    }

    public List<ResumeLog> findListByCorp(String corpCode,
                                          Integer userId,
                                          Integer category) {
        return resumeLogDao.findListByCorp(corpCode, userId, category);
    }

    public List<ResumeLog> findListByCorpAndResume(String corpCode,
                                                   Integer userId,
                                                   Integer resumeId,
                                                   Integer category) {
        return resumeLogDao.findListByCorpAndResume(corpCode, userId, resumeId, category);
    }

    public int insert(ResumeLog record) {
        return resumeLogDao.insert(record);
    }
}
